﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QCodeLib.StringHelper
{
    //用StringBuilder替代 "a" + "b" 这种写法的性能
    public class StringJoiner
    {
        protected StringBuilder Builder;
        
        public StringJoiner()
        {
            Builder = new StringBuilder();
        }

        //操作符重载+
        public static StringJoiner operator +(StringJoiner self, object value)
        {
            self.Builder.Append(value);
            return self;
        }

        //隐式转换
        public static implicit operator StringJoiner(string value)
        {
            StringJoiner text = new StringJoiner();
            text.Builder.Append(value);
            return text;
        }

        //隐式转换为string
        public static implicit operator string(StringJoiner value)
        {
            return value.ToString();
        }

        public override string ToString()
        {
            return this.Builder.ToString();
        }
    }
}
